package com.neusoft.movie.v_movies.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.javabean.ResultBean;
import com.neusoft.movie.v_movies.listener.RetrofitListener;
import com.neusoft.movie.v_movies.model.UsersModel;

public class RegActivity extends BaseActivity implements RetrofitListener {
    private EditText u_name,u_phone,u_pass,u_email,u_address,u_personal;
    private Button reg_button;
    private ImageView left;
    @Override
    void initViews() {
        setLayout(R.layout.activity_reg);
        u_name=(EditText) findViewById(R.id.u_name);
        u_phone=(EditText) findViewById(R.id.u_phone);
        u_pass=(EditText) findViewById(R.id.u_pass);
        u_email=(EditText) findViewById(R.id.u_email);
        u_address=(EditText) findViewById(R.id.u_address);
        u_personal=(EditText) findViewById(R.id.u_personal);

        left = (ImageView) findViewById(R.id.left);

        reg_button=(Button) findViewById(R.id.reg_button);
    }

    @Override
    void initEvents() {
//        reg_button.setOnClickListener(this);
//        left.setOnClickListener(this);

        //处理注册按钮
        reg_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getUserRegister();

            }
        });
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }




    @Override
    void initData() {


    }

void getUserRegister(){
    UsersModel usersModel = new UsersModel();
    usersModel.getUserRegister(
            u_name.getText().toString(),
            u_phone.getText().toString(),
            u_pass.getText().toString(),
            u_email.getText().toString(),
            u_address.getText().toString(),
            u_personal.getText().toString(),this);
}


    @Override
    public void onSuccess(Object o, int flag) {
        if (((ResultBean)o).getSuccess().equals("1")) {
            Toast.makeText(RegActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
            Intent intent1 = new Intent();
            setResult(RESULT_OK, intent1);
            finish();
        } else if(((ResultBean)o).getSuccess().equals("3")){
            Toast.makeText(RegActivity.this, "电话号码被占用", Toast.LENGTH_SHORT).show();
        }
        else if(((ResultBean)o).getSuccess().equals("2")){
            Toast.makeText(RegActivity.this, "用户名被占用", Toast.LENGTH_SHORT).show();
        }
        else {
            Toast.makeText(RegActivity.this, "注册失败", Toast.LENGTH_SHORT).show();



        }
    }

    @Override
    public void onFailed() {
        showToast("网络发生错误");
    }
}
